#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
    int value;
    struct Node *next;
}Node;

Node *createNode(int value){
    Node *newNode = (Node*)malloc(sizeof(Node));
    newNode->value = value;
    newNode->next = NULL;
    return newNode;
}

Node *copyList(Node *root){
    Node *newHead = NULL;
    Node *current2 = newHead;
    Node *current = root;
    while (current!=NULL){
        Node *newNode = createNode(current->value);
        if (newHead==NULL){
            newHead=newNode;
            current2=newHead;
        }
        else{
            current2->next=newNode;
            current2=current2->next;
        }
        current=current->next;
    }
    return newHead;
}

Node *reverseCopy(Node *root){
    
    Node *current=NULL,*left=NULL,*right;
    Node *read=root;
    while (read!=NULL){
        Node *newNode = createNode(read->value);
        if (current==NULL){
            current=newNode;
        }
        else{
            right=newNode;
            current->next=left;
            left=current;
            current=right;
        }
        read=read->next;
    }
    current->next=left;
    return current;

}

Node *sortedCopy(Node *root){
    Node *root2=copyList(root);
    Node *right,*current;
    int tag=0;
    while (tag==0&&root2!=NULL){
        tag=1;
        current=root2;
        right=current->next;
        while (right!=NULL){
            if (current->value>right->value){
                int temp=current->value;
                current->value=right->value;
                right->value=temp;
                tag=0;
            }
            current=current->next;
            right=right->next;
        }
    }
    return root2;

}

int main(){
    int n;
    scanf("%d",&n);
    Node *head =NULL;
    Node *current=head;
    for (int i=0;i<n;i++){
        int value;
        scanf("%d",&value);
        Node *newnode=createNode(value);
        if (current==NULL){
            head=newnode;
            current=head;
        }
        else{
            current->next=newnode;
            current=current->next;
        }
    }
    Node *new1=copyList(head);
    while (new1 != NULL) {
        printf("%d ", new1->value);
        new1 = new1->next;
    }
    printf("\n");
        
    Node *new2=reverseCopy(head);
    while (new2 != NULL) {
        printf("%d ", new2->value);
        new2 = new2->next;
    }
    printf("\n");

    Node *new3=sortedCopy(head);
    while (new3 != NULL) {
        printf("%d ", new3->value);
        new3 = new3->next;
    }
    printf("\n");
    return 0;

}